using System.Linq;
using DeploymentWang.Interfaces;
using DeploymentWang.Interfaces.Entities;

namespace DeploymentWang.Core.Readers
{
    public class ConfigReaderExcel : ExcelReaderBase<ConfigSetting>, IReader<SettingsRequest, ConfigSettings>
    {
        public ConfigReaderExcel(string filename)
            : base(filename)
        {
        }

        public bool Read(SettingsRequest request, out ConfigSettings settings)
        {
            var data = GetData(request.Application).Cast<ConfigSetting>();

            settings = new ConfigSettings();
            settings.AddRange((from s in data
                               where s.Environment == request.Environment 
                               select s));

            return (settings.Count > 0);
        }
    }
}